package com.hjxr.xmgl.web.controller;

import java.util.List;

import com.hjxr.framework.web.domain.AjaxResult;
import com.hjxr.sysadmin.uitl.poi.ExcelUtil;
import com.hjxr.sysadmin.web.page.TableDataInfo;
import com.hjxr.xmgl.web.domain.QuotaCategory;
import com.hjxr.xmgl.web.service.IQuotaCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hjxr.framework.aspectj.lang.annotation.Log;
import com.hjxr.framework.aspectj.lang.enums.BusinessType;


/**
 * 指标分类管理Controller
 *
 * @author hjxr
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/system/category")
public class QuotaCategoryController extends BaseController
{
    @Autowired
    private IQuotaCategoryService quotaCategoryService;

    /**
     * 查询指标分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuotaCategory quotaCategory)
    {
        startPage();
        List<QuotaCategory> list = quotaCategoryService.selectQuotaCategoryList(quotaCategory);
        return getDataTable(list);
    }

    /**
     * 导出指标分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "指标分类管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuotaCategory quotaCategory)
    {
        List<QuotaCategory> list = quotaCategoryService.selectQuotaCategoryList(quotaCategory);
        ExcelUtil<QuotaCategory> util = new ExcelUtil<QuotaCategory>(QuotaCategory.class);
        return util.exportExcel(list, "category");
    }

    /**
     * 获取指标分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{catId}")
    public AjaxResult getInfo(@PathVariable("catId") String catId)
    {
        return AjaxResult.success(quotaCategoryService.selectQuotaCategoryById(catId));
    }

    /**
     * 新增指标分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "指标分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuotaCategory quotaCategory)
    {
        return toAjax(quotaCategoryService.insertQuotaCategory(quotaCategory));
    }

    /**
     * 修改指标分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "指标分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuotaCategory quotaCategory)
    {
        return toAjax(quotaCategoryService.updateQuotaCategory(quotaCategory));
    }

    /**
     * 删除指标分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "指标分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{catIds}")
    public AjaxResult remove(@PathVariable String[] catIds)
    {
        return toAjax(quotaCategoryService.deleteQuotaCategoryByIds(catIds));
    }
}
